<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<link rel="stylesheet" href="http://127.0.0.1/hdwy/wasai/Application/Admin/View/Public/Css/common.css" />
	<link rel="stylesheet" type="text/css" href="http://127.0.0.1/hdwy/wasai/Static/bootstrap/css/bootstrap.min.css"/>
	<script type="text/javascript" src="http://127.0.0.1/hdwy/wasai/Application/Admin/View/Public/Js/jquery-1.7.2.min.js"></script>

    <script type="text/javascript">
    	$(function(){
    		//所有子集分类隐藏
    		$('tr[pid!=0]').hide();
    		//点击展开和收缩
    		$('.click-btn').toggle(function(){
    			//获得cid
    			var cid = $(this).parents('tr').attr('cid');
    			//子分类显示
    			$('tr[pid='+cid+']').show();
    			//删除+变成-
    			$(this).removeClass('glyphicon-plus').addClass('glyphicon-minus');
    		},function(){
    			//获得cid
    			var cid = $(this).parents('tr').attr('cid');
    			//异步
    			$.ajax({
    				type:"post",
    				url:"<?php echo U('Admin/Category/getSon');?>",
    				data:{cid : cid},
    				dataType:'json',
    				success:function(phpData){
    					$.each(phpData, function(k,v) {    
    						//让所有子集分类的tr隐藏
    						$('tr[cid='+v+']').hide();                                                        
    					});
    				}
    			});    		    			
    			//删除-变成+
    			$(this).removeClass('glyphicon-minus').addClass('glyphicon-plus');
    		})    		
    	})
    </script>
</head>
<body>
	<form action="" method="post">
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<table class="table table-bordered table-hover">
						<thead>
							<tr pid="0">
								<th width="30px">
								</th>
								<th>
									分类ID
								</th>
								<th>
									分类名称
								</th>
								<th>
									排序
								</th>
								<th>
									操作
								</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach ($data as $k=>$v){?>
							<tr class="info" pid="<?php echo $v['pid'];?>" cid="<?php echo $v['cid'];?>">
				        		<td width="30px">
				        			<a href="javascript:;" class="glyphicon glyphicon-plus click-btn"></a>
				        		</td>								
								<td>
								<?php echo $v['cid'];?>	
								</td>
								<td class='open'>
								<?php echo $v['_name'];?>	
								</td>
								<td>
									<input type="text" name='csort' value='<?php echo $v['csort'];?>'/>
								</td>
								<td>
									<a href="<?php echo U('addSon',array('cid'=>$v['cid']));?>" class="btn btn-success"><i class="icon-edit icon-white"></i>添加子分类</a>
									<a href="<?php echo U('edit',array('cid'=>$v['cid']));?>" class="btn btn-warning"><i class="icon-pencil icon-white"></i>修改</a>
									<a href="<?php echo U('del',array('cid'=>$v['cid']));?>" class="btn btn-danger"><i class="icon-trash icon-white"></i>删除</a>
								</td>
							</tr>
							<?php }?>
							<tr pid="0">
								<td style="border-style: none;">
									<!--<input type="hidden" name='table' value='category' />-->
									<input type="submit" value='排序' class="btn btn-primary"/>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</form>
</body>
</html>